<?PHP
  include('installer/urlrewriting.php');
  include('installer/installer.php');
  session_start();
  if(isset($_GET['restart']) && $_GET['restart']){
    $_SESSION['installer'] = null;
  }
  if(!isset($_SESSION['installer'])){
    $_SESSION['installer'] = new Installer();
  }


  if($_SESSION['installer']->validateCurrentStep()) {
    if((isset($_POST['next']) && $_POST['next']&& ($_SESSION['installer']->step == $_POST['next_id']) ) || (isset($_POST['finish']) && $_POST['finish'])){
      $_SESSION['installer']->params[$_SESSION['installer']->step-1] = $_POST;
      $_SESSION['installer']->step++;
    }
    if(isset($_POST['back']) && isset($_POST['last_id']) && $_POST['back'] && $_SESSION['installer']->step-1 == $_POST['last_id']){
      $_SESSION['installer']->step--;
    }
  }
?>
<html>
  <head>
    <title>Installation ContentLion</title>
    <style>
      body{
        background-color:#000;
        color:#fff;
        font-family:Tahoma;
        padding-top:50px;
        padding-left:25px;
      }
      .ready{
        color:#aaa;
      }
      .current{
        font-style:italic;
      }
      #logo{
        float:right;
        margin:50px;
      }
      #navigation{
        margin-top:20px;
      }
      #btnBack{
        float:left;
        margin-right:200px;
      }
      a{
        color:#fff;
      }
      a:visited{
        color:#fff;
      }
      #content{
        width:400px;
      }
      .right{
        color:#0f0;
      }
      .wrong{
        color:#f00;
      }
	  img{
		border:none;
	  }
    </style>
    <script type="text/javascript"> window.onload = function() { document.getElementById('btnNext').focus(); } </script> 
  </head>
  <body>
    <img id="logo" src="http://images.contentlion.org/logos/logo-377-295.png" /><br />
    <?php echo $_SESSION['installer']->languageChanger; ?>
    <ol>
      <?PHP
        $i = 1;
        foreach($_SESSION['installer']->steps as $step){
          echo "<li ";
          if($i < $_SESSION['installer']->step){
            echo "class='ready'>";
          }
          elseif($i == $_SESSION['installer']->step){
            echo "class='current'>";
          }
          else{
            echo "class='wait'>";
          }
          echo $_SESSION['installer']->getText($step['headline'])."</li>";
          $i++; 
        }
      ?>
    </ol>
    <h1><?PHP echo $_SESSION['installer']->getHeadline(); ?></h1>
    <form action="install.php" method="POST">
      <?PHP
        echo $_SESSION['installer']->getContent();
        if(!$_SESSION['installer']->isInstalled){
      ?>
        <div id="navigation">
          <?PHP
            if($_SESSION['installer']->showBackButton()){
            echo '<input type="hidden" name="last_id" value="'.$_SESSION['installer']->getBackButtonID().'" />';      
          ?>
          <input id="btnBack" tabindex="3" type="submit" name="back" value="<?php echo $_SESSION['installer']->getText('{button_back}');?>" />
          <?PHP
            }
            if($_SESSION['installer']->showNextButton()){
                echo '<input type="hidden" name="next_id" value="'.$_SESSION['installer']->getNextButtonID().'" />';  
          ?>
          <input id="btnNext" tabindex="2" type="submit" name="next" value="<?php echo $_SESSION['installer']->getText('{button_next}');?>" />
          <?PHP
            }
            if($_SESSION['installer']->showFinishButton()){
                echo '<input type="hidden" name="next_id" value="'.$_SESSION['installer']->getNextButtonID().'" />';
          ?>
          <input id="btnFinish" tabindex="1" type="submit" name="finish" value="<?php echo $_SESSION['installer']->getText('{button_last}');?>" />
          <?PHP
            }
          }
          else{
            $_SESSION['installer']->renameIndex();
			$redirect = "login.html";
			if(!$_SESSION['installer']->hasModRewrite()){
				$redirect = "index.php?include=login";
			}
            $_SESSION['installer']->destroy();
            ?>
            <script language="JavaScript"><!--
var zeit=(new Date()).getTime(); 
var stoppZeit=zeit+3000; 
while((new Date()).getTime()<stoppZeit){}; 
window.location.href="<?PHP echo $redirect; ?>";
// --></script> 
            <?PHP
          }
        ?>
      </div>
    </form>
  </body>
</html>
